﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using DelonixRegiaHotel.Classes;
using DelonixRegiaHotel.DBManager;
using System.Drawing.Printing;

namespace DelonixRegiaHotel
{
    public partial class CheckOut : Form
    {
        ArrayList tempCheckOut = new ArrayList();
        ArrayList tempCheckInDetails = new ArrayList();
        ArrayList temp = new ArrayList();
        string checkID;
        decimal balance;



        public CheckOut()
        {

            InitializeComponent();

        }



        private void btnCheckNric_Click(object sender, EventArgs e)
        {
            tempCheckInDetails = DelonixRegiaDB.GetcheckInDetails(tbxNRIC.Text);
            {

                foreach (var c in tempCheckInDetails)
                {
                    if (c is Customer)
                    {
                        Customer cu = new Customer();
                        cu = (Customer)c;
                        lblFirstName.Text = cu.FirstName;
                        lblLastName.Text = cu.LastName;
                        lblCustomer.Text = cu.CustomerID;
                    }
                    if (c is CheckInOut)
                    {
                        CheckInOut cio = new CheckInOut();
                        cio = (CheckInOut)c;
                        //         tbxRoomNo.Text = cio.RoomNo;
                        lblCheckID.Text = cio.CheckID;
                        checkID = cio.CheckID;
                        cboxRoomNo.Items.Add(cio.RoomNo);

                    }
                }
            }
        }

        private void cboxRoomNo_SelectedIndexChanged(object sender, EventArgs e)
        {
            string roomNo = (string)cboxRoomNo.SelectedItem;

            //CheckInOut cio = DelonixRegiaDB.getCheckInID(roomNo);
            //tbxCheckID.Text = cio.CheckID;
            CheckInOut cio = DelonixRegiaDB.getAllCheckInDetails(roomNo);
            lblNumOfAdult.Text = Convert.ToString(cio.NumOfAdult);
            lblNumOfChild.Text = Convert.ToString(cio.NumOfChild);
            lblCheckInDate.Text = Convert.ToDateTime(cio.CheckInTime).ToLongDateString();
            lblCheckOutDate.Text = Convert.ToDateTime(cio.CheckOutTime).ToLongDateString();
            lblPaymentType.Text = cio.PaymentType;
            lblNumOfKey.Text = Convert.ToString(cio.NumOfKey);
            string roomStatus = Convert.ToString(cio.RoomStatus);
            lblSubTotal.Text = Convert.ToString(cio.ExtraCostTotal);
            lblbalance.Text = Convert.ToString(cio.Balance);
            balance = cio.Balance;
            decimal total = balance + Convert.ToDecimal(lblSubTotal.Text);
            lblTotal.Text = Convert.ToString(total);

            temp = DelonixRegiaDB.getAllCheckOutExtraCost(checkID);
            dataGridView1.DataSource = temp;

            dataGridView1.Columns[0].ReadOnly = true;
            dataGridView1.Columns[1].Visible = false;
            dataGridView1.Columns[2].ReadOnly = true;
            dataGridView1.Columns[3].ReadOnly = true;

        }

        private void dataGridView1_CellPainting(object sender, DataGridViewCellPaintingEventArgs e)
        {

        }

        private void button1_Click(object sender, EventArgs e)
        {
            string roomNo = (string)cboxRoomNo.SelectedItem;
            CheckInOut cio = DelonixRegiaDB.getAllCheckInDetails(roomNo);
            string roomStatus = Convert.ToString(cio.RoomStatus);
            roomStatus = "Checked-Out";
            cio.RoomStatus = roomStatus;
            if (DelonixRegiaDB.UpdateRoomStatus(cio) == 1)
            {
                MessageBox.Show("Successfully Checked out");
                this.Hide();
            }
            else
            {
                MessageBox.Show("Error");
            }

            

        }

        private void groupBox1_Enter(object sender, EventArgs e)
        {

        }

        private void btnInvoice_Click(object sender, EventArgs e)
        {
            MessageBox.Show("" +checkID);
            GenerateInvoice form = new GenerateInvoice(Convert.ToString(checkID));
            form.ShowDialog();
            this.Close();

           
        }

   

    }
}
